package com.hdu.seckilldemo.controller;

import com.hdu.seckilldemo.service.impl.UserServiceImpl;
import com.hdu.seckilldemo.vo.LoginVo;
import com.hdu.seckilldemo.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
//@RestController 默认会将返回的结果加上responseBody
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private UserServiceImpl userService;
    //登陆页面跳转
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }
    //登陆功能
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo,HttpServletRequest request,HttpServletResponse response){
        return userService.doLogin(loginVo,request,response);
    }
}
